/**    
 * @Title: WbUtil.java  
 * @Package com.haohope.framework.wb  
 * @Description: TODO(用一句话描述该文件做什么)  
 * @author 348953327@qq.com    
 * @date May 5, 2020 8:32:39 AM  
 * @version V1.0    
 */
package com.haohope.framework.wb;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.haohope.framework.accesslog.AbstractAccesslog;

/**  
 * @ClassName: WbUtil  
 * @Description: TODO(这里用一句话描述这个类的作用)  
 * @author 348953327@qq.com  
 * @date May 5, 2020 8:32:39 AM  
 *    
 */
public class FrameworkWbUtil implements ApplicationContextAware{
	private static AbstractAccesslog accesslog;
	public static void accesslog(HttpServletRequest request,String xwl) {
		try {
			accesslog.log(request, xwl);
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
	/** 
	 * <p>Title: setApplicationContext</p>  
	 * <p>Description: </p>  
	 * @param applicationContext
	 * @throws BeansException  
	 * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)  
	 */
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		Map<String,AbstractAccesslog> accesslogs = applicationContext.getBeansOfType(AbstractAccesslog.class);
		if ( null != accesslogs && accesslogs.size() > 0 ){
			for( Map.Entry<String, AbstractAccesslog> e : accesslogs.entrySet()) {
				FrameworkWbUtil.accesslog = e.getValue();
				break;
			}
		}
	}
}
